package com.qiaofang.repository;

import com.qiaofang.entity.PartnerInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

@Repository
public interface PartnerInfoRepository extends JpaRepository<PartnerInfo, Long>, JpaSpecificationExecutor {

    @Query(value = "from PartnerInfo p where p.higherId in (:companyIds) and p.accountName in (:names) and p.delFlag = 0 order by p.id asc ")
    List<PartnerInfo> listPartnerInfoByName(@Param(value = "names") Set<String> residentNameList, @Param(value = "companyIds") List<String> companyIds);

    @Query(value = "from PartnerInfo p where p.higherId in (:companyIds) and p.phone in (:phones) and p.delFlag = 0 order by p.id asc ")
    List<PartnerInfo> listPartnerInfoByPhone(@Param(value = "phones") Set<String> phoneList, @Param(value = "companyIds") List<String> companyIds);

    /**
     * 通过人员id 查询账户名称
     * @param id
     * @return
     */
    @Query(value = "SELECT p.accountName from PartnerInfo p where p.id = :id and p.delFlag = 0  ")
    String findNameById(@Param(value = "id") Long id );
}
